package day11.Object;

/**
 * @Auther:小陈的Java
 */
public class Product implements Cloneable{
    private int id;
    private String name;
    private Category category;
    public Product(int id,String name,Category category){
        this.id = id;
        this.name = name;
        this.category=category;
    }
    public Product() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", category=" + category +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args)throws Exception {
        Category category = new Category(1,"家电");
        Product product1 = new Product(1,"联想笔记本",category);
        Product product2 = (Product) product1.clone();
        product2.getCategory().setName("笔记本");
        System.out.println(product2);
        System.out.println(product1);
    }
}
class Category{
    private int id;
    private String name;
    public Category(int id,String name){
        this.id = id;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Category{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}